package com.appspot.categoryeditor;

import java.util.ArrayList;
import java.util.List;

import org.slim3.datastore.Datastore;

import com.appspot.categoryeditor.meta.CategoryMeta;
import com.appspot.categoryeditor.meta.FolderMeta;
import com.appspot.categoryeditor.meta.UserMeta;
import com.appspot.categoryeditor.model.Category;
import com.appspot.categoryeditor.model.Folder;
import com.appspot.categoryeditor.model.User;
import com.google.appengine.api.datastore.Key;

public class PrepareDataTest {

	final static UserMeta userMeta = UserMeta.get();
	final static FolderMeta folderMeta = FolderMeta.get();
	final static CategoryMeta categoryMeta = CategoryMeta.get();



public void prepareTestData() {
		User user = new User();
		Key userKey = Datastore.createKey(userMeta, "user1");
		user.setId(userKey);

		List<Folder> folders = new ArrayList<Folder>();
		List<Key> folderKeys = new ArrayList<Key>();

		for (int i = 0; i < 5; i++) {
			Folder folder = new Folder();
			String id = "folder" + (i + 1);
			Key folderKey = Datastore.createKey(userKey, folderMeta, id);

			folder.setId(folderKey);
			folder.setOrder(5 - i);
			folders.add(folder);
			folderKeys.add(folderKey);

		}

		List<Category> categories = new ArrayList<Category>();
		Key categoryKey1 = Datastore.createKey(
				folderKeys.get(0),
				categoryMeta,
				"category1-1");
		Category category1 = new Category();
		category1.setId(categoryKey1);
		category1.setOrder(2);
		category1.setContent("category1 content");
		category1.getFolderRef().setModel(folders.get(0));
		categories.add(category1);

		Key categoryKey2 = Datastore.createKey(
				folderKeys.get(0),
				categoryMeta,
				"category1-2");
		Category category2 = new Category();
		category2.setId(categoryKey2);
		category2.setOrder(1);
		category2.setContent("category2 content");
		category2.getFolderRef().setModel(folders.get(0));
		categories.add(category2);

		Key categoryKey3 = Datastore.createKey(
				folderKeys.get(1),
				categoryMeta,
				"category2-1");
		Category category3 = new Category();
		category3.setId(categoryKey3);
		category3.setOrder(1);
		category3.setContent("category3 content");
		category3.getFolderRef().setModel(folders.get(1));
		categories.add(category3);

		Key categoryKey4 = Datastore.createKey(
				folderKeys.get(2),
				categoryMeta,
				"category3-1");
		Category category4 = new Category();
		category4.setId(categoryKey4);
		category4.setOrder(1);
		category4.setContent("category4 content");
		category4.getFolderRef().setModel(folders.get(2));
		categories.add(category4);

		Datastore.put(user);
		Datastore.put(folders);
		Datastore.put(categories);
	}

}
